PACKAGE = racket

srcdir = @srcdir@
builddir = @builddir@
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
bindir = @bindir@
libdir = @libdir@
libpltdir = @libpltdir@
sharepltdir = @sharepltdir@
collectsdir = @collectsdir@

# for version.mak:
mainsrcdir = @srcdir@/../..
@INCLUDEDEP@ @srcdir@/../../version/version.mak

CC = @CC@
CPP = @CPP@
CXX = @CXX@
AR = @AR@
ARFLAGS = @ARFLAGS@
RANLIB = @RANLIB@

CFLAGS = @CFLAGS@ @COMPFLAGS@ @PROFFLAGS@
CPPFLAGS = @PREFLAGS@
RKTIO_INC = -I$(srcdir)/../../rktio -I../rktio
ALL_CPPFLAGS = -I$(builddir)/.. -I$(srcdir)/../include -I$(srcdir)/../../version $(RKTIO_INC) $(CPPFLAGS) @OPTIONS@ @GC2OPTIONS@ @MZOPTIONS@ 
ALL_CFLAGS = $(CFLAGS) $(ALL_CPPFLAGS)
LIBS = @LIBS@

LIBFFI_INCLUDE_ON = -I../foreign/libffi/include
LIBFFI_INCLUDE_OFF = 

ARLIBFLAGS = @LDFLAGS@ $(LIBS)

DEF_COLLECTS_DIR = +D INITIAL_COLLECTS_DIRECTORY='"'"`cd $(srcdir)/../../../collects; @PWD@`"'"'
DEF_CONFIG_DIR = +D INITIAL_CONFIG_DIRECTORY='"'"`cd $(srcdir)/../../..; @PWD@`/etc"'"'
DEF_C_DIRS = $(DEF_COLLECTS_DIR) $(DEF_CONFIG_DIR)

# See ../../Makefile about RUN_RACKET_CGC, which 
# typically redirects to RUN_THIS_RACKET_CGC:
RUN_THIS_RACKET_CGC = ../racket@CGC@

SETUP_BOOT = -O "info@compiler/cm error" -l- setup @BOOT_MODE@ $(srcdir)/../../setup-go.rkt ../../compiled
XFORM_SETUP = @RUN_RACKET_CGC@ $(SELF_RACKET_FLAGS) $(SETUP_BOOT) --tag ++out $(srcdir)/xform-mod.rkt --depends
XFORM_NOPRECOMP = $(XFORM_SETUP) --cpp "$(CPP) $(ALL_CPPFLAGS)" @XFORMFLAGS@ -o ++out
XSRCDIR = xsrc
XFORM = env XFORM_USE_PRECOMP=$(XSRCDIR)/precomp.h $(XFORM_NOPRECOMP)
SRCDIR = $(srcdir)/../src

FOREIGN_USED_OBJ = foreign.@LTO@
FOREIGN_NOT_USED_OBJ = $(FOREIGN_USED_OBJ)

OBJS =  salloc.@LTO@ \
	bignum.@LTO@ \
	bool.@LTO@ \
	char.@LTO@ \
	compenv.@LTO@ \
	compile.@LTO@ \
	complex.@LTO@ \
	dynext.@LTO@ \
	env.@LTO@ \
	error.@LTO@ \
	eval.@LTO@ \
	file.@LTO@ \
	fun.@LTO@ \
	future.@LTO@ \
        gmp.@LTO@ \
	hash.@LTO@ \
	jit.@LTO@ \
	jitalloc.@LTO@ \
	jitarith.@LTO@ \
	jitcall.@LTO@ \
	jitcommon.@LTO@ \
	jitinline.@LTO@ \
	jitprep.@LTO@ \
	jitstack.@LTO@ \
	jitstate.@LTO@ \
	letrec_check.@LTO@ \
	linklet.@LTO@ \
	list.@LTO@ \
	marshal.@LTO@ \
	mzrt.@LTO@ \
	network.@LTO@ \
	numarith.@LTO@ \
	number.@LTO@ \
	numcomp.@LTO@ \
	numstr.@LTO@ \
	optimize.@LTO@ \
	place.@LTO@ \
	port.@LTO@ \
	portfun.@LTO@ \
	print.@LTO@ \
	rational.@LTO@ \
	read.@LTO@ \
	regexp.@LTO@ \
	resolve.@LTO@ \
	sema.@LTO@ \
	setjmpup.@LTO@ \
	sfs.@LTO@ \
	sort.@LTO@ \
	startup.@LTO@ \
	string.@LTO@ \
	struct.@LTO@ \
	symbol.@LTO@ \
	syntax.@LTO@ \
	thread.@LTO@ \
	type.@LTO@ \
	validate.@LTO@ \
	vector.@LTO@ \
	$(@FOREIGN_IF_USED@_OBJ)

FOREIGN_USED_C = $(XSRCDIR)/foreign.c
FOREIGN_NOT_USED_C = $(FOREIGN_USED_C)

XSRCS = $(XSRCDIR)/salloc.c \
	$(XSRCDIR)/bignum.c \
	$(XSRCDIR)/bool.c \
	$(XSRCDIR)/char.c \
	$(XSRCDIR)/compenv.c \
	$(XSRCDIR)/compile.c \
	$(XSRCDIR)/complex.c \
	$(XSRCDIR)/dynext.c \
	$(XSRCDIR)/env.c \
	$(XSRCDIR)/error.c \
	$(XSRCDIR)/eval.c \
	$(XSRCDIR)/file.c \
	$(XSRCDIR)/fun.c \
	$(XSRCDIR)/future.c \
	$(XSRCDIR)/hash.c \
	$(XSRCDIR)/jit.c \
	$(XSRCDIR)/jitalloc.c \
	$(XSRCDIR)/jitarith.c \
	$(XSRCDIR)/jitcall.c \
	$(XSRCDIR)/jitcommon.c \
	$(XSRCDIR)/jitinline.c \
	$(XSRCDIR)/jitprep.c \
	$(XSRCDIR)/jitstack.c \
	$(XSRCDIR)/jitstate.c \
	$(XSRCDIR)/letrec_check.c \
	$(XSRCDIR)/linklet.c \
	$(XSRCDIR)/list.c \
	$(XSRCDIR)/marshal.c \
	$(XSRCDIR)/network.c \
	$(XSRCDIR)/numarith.c \
	$(XSRCDIR)/numcomp.c \
	$(XSRCDIR)/number.c \
	$(XSRCDIR)/numstr.c \
	$(XSRCDIR)/optimize.c \
	$(XSRCDIR)/place.c \
	$(XSRCDIR)/port.c \
	$(XSRCDIR)/portfun.c \
	$(XSRCDIR)/print.c \
	$(XSRCDIR)/rational.c \
	$(XSRCDIR)/read.c \
	$(XSRCDIR)/regexp.c \
	$(XSRCDIR)/resolve.c \
	$(XSRCDIR)/sema.c \
	$(XSRCDIR)/setjmpup.c \
	$(XSRCDIR)/sfs.c \
	$(XSRCDIR)/sort.c \
	$(XSRCDIR)/startup.c \
	$(XSRCDIR)/string.c \
	$(XSRCDIR)/struct.c \
	$(XSRCDIR)/symbol.c \
	$(XSRCDIR)/syntax.c \
	$(XSRCDIR)/thread.c \
	$(XSRCDIR)/type.c \
	$(XSRCDIR)/validate.c \
	$(XSRCDIR)/vector.c \
	$(@FOREIGN_IFUSED@_C) \
	$(XSRCDIR)/main.c

all: xsrc
	$(MAKE) check-sdep
	$(MAKE) $(XSRCDIR)/precomp.h
	$(MAKE) xobjects
	$(MAKE) ../racket3m@EXE_SUFFIX@

xsrcs: $(XSRCS)

xsrc:
	mkdir xsrc

xobjects: $(OBJS) main.@LTO@

# These headers have only preprocessor definitions, so they're not
# picked up in ".sdep":
QUIET_DEPS = $(srcdir)/../../version/racket_version.h $(srcdir)/../sconfig.h ../mzconfig.h

XFORMDEP_NOPRE = $(srcdir)/xform-mod.rkt $(QUIET_DEPS)
XFORMDEP = $(XFORMDEP_NOPRE) $(XSRCDIR)/precomp.h

MZRTDEP = $(srcdir)/../src/schpriv.h $(srcdir)/../include/scheme.h \
          $(srcdir)/../sconfig.h ../mzconfig.h $(srcdir)/../uconfig.h $(srcdir)/../src/schemef.h \
          $(srcdir)/../src/stypes.h $(srcdir)/../include/schthread.h $(srcdir)/../src/mzrt.h \
          $(srcdir)/../src/mzrt_cas.inc

# Uses ".sdep" content to dicard out-of-date ".c" and ".h" files in "xsrc":
check-sdep :
	@RUN_RACKET_CGC@ $(SELF_RACKET_FLAGS) -cqu $(srcdir)/check-sdep.rkt

$(XSRCDIR)/precomp.h : $(XFORMDEP_NOPRE)
	env XFORM_PRECOMP=yes $(XFORM_NOPRECOMP) $(XSRCDIR)/precomp.h $(srcdir)/precomp.c

$(XSRCDIR)/salloc.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/salloc.c $(SRCDIR)/salloc.c
$(XSRCDIR)/bignum.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/bignum.c $(SRCDIR)/bignum.c
$(XSRCDIR)/bool.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/bool.c $(SRCDIR)/bool.c
$(XSRCDIR)/char.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/char.c $(SRCDIR)/char.c
$(XSRCDIR)/compenv.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/compenv.c $(SRCDIR)/compenv.c
$(XSRCDIR)/compile.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/compile.c $(SRCDIR)/compile.c
$(XSRCDIR)/complex.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/complex.c $(SRCDIR)/complex.c
$(XSRCDIR)/dynext.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/dynext.c $(SRCDIR)/dynext.c
$(XSRCDIR)/env.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/env.c $(SRCDIR)/env.c
$(XSRCDIR)/error.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/error.c $(SRCDIR)/error.c
$(XSRCDIR)/eval.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/eval.c $(SRCDIR)/eval.c
$(XSRCDIR)/file.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/file.c $(SRCDIR)/file.c
$(XSRCDIR)/fun.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/fun.c $(SRCDIR)/fun.c
$(XSRCDIR)/future.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/future.c $(SRCDIR)/future.c
$(XSRCDIR)/hash.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/hash.c $(SRCDIR)/hash.c
$(XSRCDIR)/jit.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/jit.c $(SRCDIR)/jit.c
$(XSRCDIR)/jitalloc.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/jitalloc.c $(SRCDIR)/jitalloc.c
$(XSRCDIR)/jitarith.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/jitarith.c $(SRCDIR)/jitarith.c
$(XSRCDIR)/jitcall.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/jitcall.c $(SRCDIR)/jitcall.c
$(XSRCDIR)/jitcommon.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/jitcommon.c $(SRCDIR)/jitcommon.c
$(XSRCDIR)/jitinline.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/jitinline.c $(SRCDIR)/jitinline.c
$(XSRCDIR)/jitprep.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/jitprep.c $(SRCDIR)/jitprep.c
$(XSRCDIR)/jitstack.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/jitstack.c $(SRCDIR)/jitstack.c
$(XSRCDIR)/jitstate.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/jitstate.c $(SRCDIR)/jitstate.c
$(XSRCDIR)/marshal.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/marshal.c $(SRCDIR)/marshal.c
$(XSRCDIR)/letrec_check.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/letrec_check.c $(SRCDIR)/letrec_check.c
$(XSRCDIR)/linklet.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/linklet.c $(SRCDIR)/linklet.c
$(XSRCDIR)/list.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/list.c $(SRCDIR)/list.c
$(XSRCDIR)/network.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/network.c $(SRCDIR)/network.c
$(XSRCDIR)/numarith.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/numarith.c $(SRCDIR)/numarith.c
$(XSRCDIR)/number.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/number.c $(SRCDIR)/number.c
$(XSRCDIR)/numcomp.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/numcomp.c $(SRCDIR)/numcomp.c
$(XSRCDIR)/numstr.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/numstr.c $(SRCDIR)/numstr.c
$(XSRCDIR)/optimize.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/optimize.c $(SRCDIR)/optimize.c
$(XSRCDIR)/place.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/place.c $(SRCDIR)/place.c
$(XSRCDIR)/port.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/port.c $(SRCDIR)/port.c
$(XSRCDIR)/portfun.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/portfun.c $(SRCDIR)/portfun.c
$(XSRCDIR)/print.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/print.c $(SRCDIR)/print.c
$(XSRCDIR)/rational.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/rational.c $(SRCDIR)/rational.c
$(XSRCDIR)/read.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/read.c $(SRCDIR)/read.c
$(XSRCDIR)/regexp.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/regexp.c $(SRCDIR)/regexp.c
$(XSRCDIR)/resolve.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/resolve.c $(SRCDIR)/resolve.c
$(XSRCDIR)/sema.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/sema.c $(SRCDIR)/sema.c
$(XSRCDIR)/setjmpup.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/setjmpup.c $(SRCDIR)/setjmpup.c
$(XSRCDIR)/sfs.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/sfs.c $(SRCDIR)/sfs.c
$(XSRCDIR)/sort.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/sort.c $(SRCDIR)/sort.c
$(XSRCDIR)/startup.c: $(XFORMDEP) ../cstartup.inc $(SRCDIR)/startup-glue.inc
	$(XFORM_SETUP) --cpp "$(CPP) -I.. -I$(SRCDIR)/../src $(ALL_CPPFLAGS)" @XFORMFLAGS@ -o ++out $(XSRCDIR)/startup.c $(SRCDIR)/startup.c
$(XSRCDIR)/string.c: $(XFORMDEP)  $(SRCDIR)/systype.inc
	$(XFORM_SETUP) --cpp "$(CPP) -I../src $(ALL_CPPFLAGS)" @XFORMFLAGS@ -o ++out $(XSRCDIR)/string.c $(SRCDIR)/string.c
$(XSRCDIR)/struct.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/struct.c $(SRCDIR)/struct.c
$(XSRCDIR)/symbol.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/symbol.c $(SRCDIR)/symbol.c
$(XSRCDIR)/syntax.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/syntax.c $(SRCDIR)/syntax.c
$(XSRCDIR)/thread.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/thread.c $(SRCDIR)/thread.c
$(XSRCDIR)/type.c: $(XFORMDEP) $(MZCLPFDEP)
	$(XFORM) $(XSRCDIR)/type.c $(SRCDIR)/type.c
$(XSRCDIR)/validate.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/validate.c $(SRCDIR)/validate.c
$(XSRCDIR)/vector.c: $(XFORMDEP)
	$(XFORM) $(XSRCDIR)/vector.c $(SRCDIR)/vector.c
$(XSRCDIR)/foreign.c: $(XFORMDEP)
	$(XFORM_SETUP) --cpp "$(CPP) $(ALL_CPPFLAGS) $(LIBFFI_INCLUDE_@OWN_LIBFFI@) -I${SRCDIR}/../src" @XFORMFLAGS@ -o ++out $(XSRCDIR)/foreign.c $(SRCDIR)/../foreign/foreign.c
$(XSRCDIR)/main.c: $(XFORMDEP)
	$(XFORM_NOPRECOMP) $(XSRCDIR)/main.c $(DEF_C_DIRS) $(srcdir)/../main.c

@INCLUDEDEP@ salloc.d
@INCLUDEDEP@ bignum.d
@INCLUDEDEP@ bool.d
@INCLUDEDEP@ char.d
@INCLUDEDEP@ compenv.d
@INCLUDEDEP@ compile.d
@INCLUDEDEP@ complex.d
@INCLUDEDEP@ dynext.d
@INCLUDEDEP@ env.d
@INCLUDEDEP@ error.d
@INCLUDEDEP@ eval.d
@INCLUDEDEP@ file.d
@INCLUDEDEP@ fun.d
@INCLUDEDEP@ future.d
@INCLUDEDEP@ gmp.d
@INCLUDEDEP@ hash.d
@INCLUDEDEP@ jit.d
@INCLUDEDEP@ jitalloc.d
@INCLUDEDEP@ jitarith.d
@INCLUDEDEP@ jitcall.d
@INCLUDEDEP@ jitcommon.d
@INCLUDEDEP@ jitinline.d
@INCLUDEDEP@ jitprep.d
@INCLUDEDEP@ jitstack.d
@INCLUDEDEP@ jitstate.d
@INCLUDEDEP@ letrec_check.d
@INCLUDEDEP@ linklet.d
@INCLUDEDEP@ list.d
@INCLUDEDEP@ marshal.d
@INCLUDEDEP@ mzrt.d
@INCLUDEDEP@ network.d
@INCLUDEDEP@ numarith.d
@INCLUDEDEP@ number.d
@INCLUDEDEP@ numcomp.d
@INCLUDEDEP@ numstr.d
@INCLUDEDEP@ optimize.d
@INCLUDEDEP@ place.d
@INCLUDEDEP@ port.d
@INCLUDEDEP@ portfun.d
@INCLUDEDEP@ print.d
@INCLUDEDEP@ rational.d
@INCLUDEDEP@ read.d
@INCLUDEDEP@ regexp.d
@INCLUDEDEP@ resolve.d
@INCLUDEDEP@ sema.d
@INCLUDEDEP@ setjmpup.d
@INCLUDEDEP@ sfs.d
@INCLUDEDEP@ sort.d
@INCLUDEDEP@ startup.d
@INCLUDEDEP@ string.d
@INCLUDEDEP@ struct.d
@INCLUDEDEP@ symbol.d
@INCLUDEDEP@ syntax.d
@INCLUDEDEP@ thread.d
@INCLUDEDEP@ type.d
@INCLUDEDEP@ validate.d
@INCLUDEDEP@ vector.d
@INCLUDEDEP@ foreign.d
@INCLUDEDEP@ main.d

CMDL_DEPS = $(srcdir)/../../start/parse_cmdl.inc $(srcdir)/../../start/cmdl_to_argv.inc

$(XSRCDIR)/mzobj.cxx: $(XFORMDEP) $(srcdir)/../../mzcom/mzobj.cxx $(CMDL_DEPS)
	$(XFORM_NOPRECOMP) $(XSRCDIR)/mzobj.cxx $(DEF_C_DIRS) $(srcdir)/../../mzcom/mzobj.cxx

salloc.@LTO@: $(XSRCDIR)/salloc.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/salloc.c -o salloc.@LTO@
bignum.@LTO@: $(XSRCDIR)/bignum.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/bignum.c -o bignum.@LTO@
bool.@LTO@: $(XSRCDIR)/bool.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/bool.c -o bool.@LTO@
char.@LTO@: $(XSRCDIR)/char.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/char.c -o char.@LTO@
compenv.@LTO@: $(XSRCDIR)/compenv.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/compenv.c -o compenv.@LTO@
compile.@LTO@: $(XSRCDIR)/compile.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/compile.c -o compile.@LTO@
complex.@LTO@: $(XSRCDIR)/complex.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/complex.c -o complex.@LTO@
dynext.@LTO@: $(XSRCDIR)/dynext.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/dynext.c -o dynext.@LTO@
env.@LTO@: $(XSRCDIR)/env.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/env.c -o env.@LTO@
error.@LTO@: $(XSRCDIR)/error.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/error.c -o error.@LTO@
eval.@LTO@: $(XSRCDIR)/eval.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/eval.c -o eval.@LTO@
file.@LTO@: $(XSRCDIR)/file.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/file.c -o file.@LTO@
fun.@LTO@: $(XSRCDIR)/fun.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/fun.c -o fun.@LTO@
future.@LTO@: $(XSRCDIR)/future.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/future.c -o future.@LTO@
gmp.@LTO@: $(srcdir)/../src/gmp/gmp.c $(srcdir)/../src/gmp/gmplonglong.h \
           $(srcdir)/../include/schthread.h $(srcdir)/../sconfig.h
	$(CC) $(ALL_CFLAGS) -DMZ_PRECISE_GC -c $(srcdir)/../src/gmp/gmp.c -o gmp.@LTO@
hash.@LTO@: $(XSRCDIR)/hash.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/hash.c -o hash.@LTO@
jit.@LTO@: $(XSRCDIR)/jit.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/jit.c -o jit.@LTO@
jitalloc.@LTO@: $(XSRCDIR)/jitalloc.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/jitalloc.c -o jitalloc.@LTO@
jitarith.@LTO@: $(XSRCDIR)/jitarith.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/jitarith.c -o jitarith.@LTO@
jitcall.@LTO@: $(XSRCDIR)/jitcall.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/jitcall.c -o jitcall.@LTO@
jitcommon.@LTO@: $(XSRCDIR)/jitcommon.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/jitcommon.c -o jitcommon.@LTO@
jitinline.@LTO@: $(XSRCDIR)/jitinline.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/jitinline.c -o jitinline.@LTO@
jitprep.@LTO@: $(XSRCDIR)/jitprep.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/jitprep.c -o jitprep.@LTO@
jitstack.@LTO@: $(XSRCDIR)/jitstack.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/jitstack.c -o jitstack.@LTO@
jitstate.@LTO@: $(XSRCDIR)/jitstate.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/jitstate.c -o jitstate.@LTO@
letrec_check.@LTO@: $(XSRCDIR)/letrec_check.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/letrec_check.c -o letrec_check.@LTO@
linklet.@LTO@: $(XSRCDIR)/linklet.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/linklet.c -o linklet.@LTO@
list.@LTO@: $(XSRCDIR)/list.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/list.c -o list.@LTO@
marshal.@LTO@: $(XSRCDIR)/marshal.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/marshal.c -o marshal.@LTO@
mzrt.@LTO@: $(SRCDIR)/mzrt.c $(XFORMDEP) $(MZRTDEP)
	$(CC) $(ALL_CFLAGS) -DMZ_PRECISE_GC -c $(SRCDIR)/mzrt.c -o mzrt.@LTO@
network.@LTO@: $(XSRCDIR)/network.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/network.c -o network.@LTO@
numarith.@LTO@: $(XSRCDIR)/numarith.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/numarith.c -o numarith.@LTO@
number.@LTO@: $(XSRCDIR)/number.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/number.c -o number.@LTO@
numcomp.@LTO@: $(XSRCDIR)/numcomp.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/numcomp.c -o numcomp.@LTO@
numstr.@LTO@: $(XSRCDIR)/numstr.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/numstr.c -o numstr.@LTO@
optimize.@LTO@: $(XSRCDIR)/optimize.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/optimize.c -o optimize.@LTO@
place.@LTO@: $(XSRCDIR)/place.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/place.c -o place.@LTO@
port.@LTO@: $(XSRCDIR)/port.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/port.c -o port.@LTO@
portfun.@LTO@: $(XSRCDIR)/portfun.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/portfun.c -o portfun.@LTO@
print.@LTO@: $(XSRCDIR)/print.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/print.c -o print.@LTO@
rational.@LTO@: $(XSRCDIR)/rational.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/rational.c -o rational.@LTO@
read.@LTO@: $(XSRCDIR)/read.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/read.c -o read.@LTO@
regexp.@LTO@: $(XSRCDIR)/regexp.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/regexp.c -o regexp.@LTO@
resolve.@LTO@: $(XSRCDIR)/resolve.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/resolve.c -o resolve.@LTO@
sema.@LTO@: $(XSRCDIR)/sema.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/sema.c -o sema.@LTO@
setjmpup.@LTO@: $(XSRCDIR)/setjmpup.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/setjmpup.c -o setjmpup.@LTO@
sfs.@LTO@: $(XSRCDIR)/sfs.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/sfs.c -o sfs.@LTO@
sort.@LTO@: $(XSRCDIR)/sort.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/sort.c -o sort.@LTO@
startup.@LTO@: $(XSRCDIR)/startup.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/startup.c -o startup.@LTO@
string.@LTO@: $(XSRCDIR)/string.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/string.c -o string.@LTO@
struct.@LTO@: $(XSRCDIR)/struct.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/struct.c -o struct.@LTO@
symbol.@LTO@: $(XSRCDIR)/symbol.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/symbol.c -o symbol.@LTO@
syntax.@LTO@: $(XSRCDIR)/syntax.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/syntax.c -o syntax.@LTO@
thread.@LTO@: $(XSRCDIR)/thread.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/thread.c -o thread.@LTO@
type.@LTO@: $(XSRCDIR)/type.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/type.c -o type.@LTO@
validate.@LTO@: $(XSRCDIR)/validate.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/validate.c -o validate.@LTO@
vector.@LTO@: $(XSRCDIR)/vector.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/vector.c -o vector.@LTO@
foreign.@LTO@: $(XSRCDIR)/foreign.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/foreign.c -o foreign.@LTO@
main.@LTO@: $(XSRCDIR)/main.c
	$(CC) $(ALL_CFLAGS) -c $(XSRCDIR)/main.c -o main.@LTO@

gmp_alpha_gcc.@LTO@: $(SRCDIR)/gmp/gmp_alpha_gcc.s
	$(AS) -o gmp_alpha_gcc.@LTO@ $(SRCDIR)/gmp/gmp_alpha_gcc.s
gmp_arm_gcc.@LTO@: $(SRCDIR)/gmp/gmp_arm_gcc.s
	$(CC) -o gmp_arm_gcc.@LTO@ -c $(SRCDIR)/gmp/gmp_arm_gcc.S

mzcom.@LTO@: $(srcdir)/../../mzcom/mzcom.cxx
	$(CC) -DMZCOM_3M $(ALL_CFLAGS) -fno-exceptions -c $(srcdir)/../../mzcom/mzcom.cxx -o mzcom.@LTO@
mzobj.@LTO@: $(XSRCDIR)/mzobj.cxx
	$(CC) $(ALL_CFLAGS) -fno-exceptions -c $(XSRCDIR)/mzobj.cxx -o mzobj.@LTO@

gc2.@LTO@: \
		$(srcdir)/alloc_cache.c \
		$(srcdir)/block_cache.c \
		$(srcdir)/backtrace.c \
		$(srcdir)/commongc_internal.h \
		$(srcdir)/platforms.h \
		$(srcdir)/fnls.c \
		$(srcdir)/gc2.c \
		$(srcdir)/gc2.h \
		$(srcdir)/gc2_dump.h \
		$(srcdir)/gc2_obj.h \
		$(srcdir)/immobile_boxes.c \
		$(srcdir)/../include/scheme.h \
		$(srcdir)/../include/schthread.h \
		$(srcdir)/../sconfig.h \
		../mzconfig.h \
		$(srcdir)/../uconfig.h \
		$(srcdir)/../src/stypes.h \
		$(srcdir)/../src/schexn.h \
		$(srcdir)/../gc2/gc2.h \
		$(srcdir)/../src/schemef.h \
		$(builddir)/../mzconfig.h \
		$(srcdir)/../src/mzrt.h \
		$(srcdir)/../src/schpriv.h \
		$(srcdir)/../utils/splay.c \
		$(srcdir)/mem_account.c \
		$(srcdir)/msgprint.c \
		$(srcdir)/my_qsort.c \
		$(srcdir)/newgc.c \
		$(srcdir)/newgc.h \
		$(srcdir)/page_range.c \
		$(srcdir)/places_gc.c \
		$(srcdir)/rlimit_heapsize.c \
		$(srcdir)/roots.c \
		$(srcdir)/stack_comp.c \
		$(srcdir)/sighand.c \
		$(srcdir)/var_stack.c \
		$(srcdir)/vm.c \
		$(srcdir)/vm_memalign.c \
		$(srcdir)/vm_mmap.c \
		$(srcdir)/vm_osk.c \
		$(srcdir)/vm_osx.c \
		$(srcdir)/weak.c
	$(CC) $(ALL_CFLAGS) -I$(builddir)/.. -c $(srcdir)/gc2.c -o gc2.@LTO@

FOREIGN_OBJS_ON = ../foreign/libffi/src/*.@LTO@ ../foreign/libffi/src/*/*.@LTO@
FOREIGN_LIB_ON = ../foreign/libffi/libffi@FOREIGN_CONVENIENCE@.la
FOREIGN_OBJS_OFF =
FOREIGN_LIB_OFF =
FOREIGN_OBJS = $(FOREIGN_OBJS_@OWN_LIBFFI@)
FOREIGN_LIB = $(FOREIGN_LIB_@OWN_LIBFFI@)
FOREIGN_OBJSLIB = @FOREIGN_OBJSLIB@

FOREIGN_USED_LIB = $(FOREIGN_OBJ) $(FOREIGN_LIB)
FOREIGN_USED_OBJSLIB = $(FOREIGN_OBJSLIB)
FOREIGN_NOT_USED_LIB = $(FOREIGN_OBJ)
FOREIGN_NOT_USED_OBJSLIB = 

LIBRKTIO = ../rktio/librktio.@LTA@
LIBRKTIO_FOR_DLL_la = $(LIBRKTIO)
LIBRKTIO_FOR_DLL_a = 
LIBRKTIO_FOR_LIB_la =
LIBRKTIO_FOR_LIB_a = $(LIBRKTIO)
LIBRKTIO_UP_FOR_LIB_la =
LIBRKTIO_UP_FOR_LIB_a = gc2/$(LIBRKTIO)
LIBRKTIO_FOR_DLL = $(LIBRKTIO_FOR_DLL_@LIBSFX@)
LIBRKTIO_FOR_LIB = $(LIBRKTIO_FOR_LIB_@LIBSFX@)
LIBRKTIO_UP_FOR_LIB = $(LIBRKTIO_UP_FOR_LIB_@LIBSFX@)

LTO=@LTO@ # Need for replacement of EXTRA_GMP_OBJ which carries the variable
EXTRA_GMP_DEP_FILE = @EXTRA_GMP_OBJ@
EXTRA_GMP = @EXTRA_GMP_DEP@

EXTRA_OBJS_T = $(EXTRA_GMP) ../src/unwind.@LTO@ $(@FOREIGN_IF_USED@_LIB) $(LIBRKTIO_FOR_DLL)
EXTRA_OBJS_L = $(EXTRA_GMP) ../src/unwind.@LTO@ $(@FOREIGN_IF_USED@_OBJSLIB) $(LIBRKTIO_FOR_DLL)

../libracket3m.@LIBSFX@: $(OBJS) $(EXTRA_OBJS_T) gc2.@LTO@
	$(AR) $(ARFLAGS) ../libracket3m.@LIBSFX@ $(OBJS) $(EXTRA_OBJS_L) gc2.@LTO@

../racket@MMM@@NOT_OSX@@NOT_MINGW@: main.@LTO@ ../libracket3m.@LIBSFX@ $(LIBRKTIO_FOR_LIB)
	cd ..; @MZLINKER@ -o racket@MMM@ @PROFFLAGS@ gc2/main.@LTO@ libracket3m.@LIBSFX@ $(LIBRKTIO_UP_FOR_LIB) @LDFLAGS@ $(LIBS)
	@POST_LINKER@ ../racket@MMM@

# The above "cd .." prevents a problem with libtool's generated script in --enable-shared mode,
#  at least for Mac OS X. Beware of changing LIBS or LDFLAGS to inclucde something with a relative
#  path.

MZFWMMM = Racket.framework/Versions/$(FWVERSION)_3m/Racket
MZFWMMM_DEST = "../Racket.framework/Versions/$(FWVERSION)_3m/Racket"

MACLIBRKT_LIBS = ../libracket3m.@LIBSFX@ $(LIBRKTIO) -framework CoreFoundation

$(MZFWMMM): ../libracket3m.@LIBSFX@ $(LIBRKTIO)
	mkdir -p "Racket.framework/Versions/$(FWVERSION)_3m"
	@MZLINKER@ -o $(MZFWMMM) -dynamiclib -all_load $(MACLIBRKT_LIBS) @LDFLAGS@ $(LIBS)
	rm -f Racket.framework/Racket
	ln -s Versions/$(FWVERSION)_3m/Racket Racket.framework/Racket	
	mkdir -p "../Racket.framework/Versions/$(FWVERSION)_3m"
	rm -f $(MZFWMMM_DEST)
	cp "Racket.framework/Racket" $(MZFWMMM_DEST)

# Depending on MACLIBRKT_LINK_MODE, use Framework or statically link the framework's code:
MACLIBRKT_LINK_fw = -F. -framework Racket
MACLIBRKT_LINK_static = $(MACLIBRKT_LIBS)

../racket@MMM@@OSX@: $(MZFWMMM) main.@LTO@
	@MZLINKER@ -o ../racket@MMM@ @PROFFLAGS@ @LDFLAGS@ main.@LTO@ -Wl,-headerpad_max_install_names $(MACLIBRKT_LINK_@MACLIBRKT_LINK_MODE@) @LIBS@
	@STRIP_SIGNATURE@ "../racket@MMM@"
	/usr/bin/install_name_tool -change "Racket.framework/Versions/$(FWVERSION)_3m/Racket" "@executable_path/Racket.framework/Versions/$(FWVERSION)_3m/Racket" "../racket@MMM@"
	@RESTORE_SIGNATURE@ "${srcdir}/../../mac/entitlements.plist" "../racket@MMM@"

../lib/libracket3mxxxxxxx.dll: ../libracket3m.@LIBSFX@ ../mzsj86g.o $(LIBRKTIO)
	mkdir -p ../lib
	@MZLINKER@ -shared -o ../lib/libracket3mxxxxxxx.dll ../mzsj86g.o -Wl,--output-def -Wl,libracket3m.def -Wl,--whole-archive ../libracket3m.@LIBSFX@ -Wl,--no-whole-archive $(LIBRKTIO) @LDFLAGS@ -lshell32 -luser32 -lws2_32 -lwinmm -static-libgcc @LIBS@

libracket3m.dll.a: ../lib/libracket3mxxxxxxx.dll
	@DLLTOOL@ --def libracket3m.def -D libracket3mxxxxxxx.dll --output-exp libracket3mxxxxxxx.exp --output-lib libracket3mxxxxxxx.lib --output-delaylib libracket3m.dll.a

MW_RACKET_LIBS = gc2/libracket3m.dll.a @LDFLAGS@ @LIBS@ -ldelayimp -static-libgcc

../racket@MMM@@EXE_SUFFIX@@MINGW@: libracket3m.dll.a main.@LTO@ ../MemoryModule.@LTO@ ../rres.o $(SPECIALIZINGOBJECTS)
	cd ..; @MZLINKER@ -o racket@MMM@@EXE_SUFFIX@ gc2/main.@LTO@ MemoryModule.@LTO@ rres.o $(SPECIALIZINGOBJECTS) $(MW_RACKET_LIBS)

../mzcom@MMM@@NOT_MINGW@:
	$(NOOP)

../mzcom@MMM@@EXE_SUFFIX@@MINGW@: libracket3m.dll.a mzcom.@LTO@ mzobj.@LTO@ ../com_glue.@LTO@ $(SPECIALIZINGOBJECTS) ../comres.o
	cd ..; @MZLINKER@ -mwindows -o mzcom@MMM@@EXE_SUFFIX@ gc2/mzcom.@LTO@ gc2/mzobj.@LTO@ com_glue.@LTO@ comres.o $(SPECIALIZINGOBJECTS) -lole32 -loleaut32 -luuid $(MW_RACKET_LIBS)

clean:
	/bin/rm -f ../racket@MMM@ *.@LTO@ $(XSRCDIR)/*
	/bin/rm -rf Racket.framework

# If "cstartup.inc" hasn't been built, yet, create it as
# a redirect to "startup.inc"
../cstartup.inc:
	echo '#include "startup.inc"' > ../cstartup.inc

#--------------------------------------------------

test.@LTO@: $(srcdir)/test.c
	$(CC) $(ALL_CFLAGS) -c $(srcdir)/test.c -o test.@LTO@

gct: test.@LTO@ gc2.@LTO@
	$(CC) -o gct test.@LTO@ gc2.@LTO@

